<script setup>
import { ref } from 'vue'

const moodStats = {
  totalEntries: 45,
  averageMood: 75,
  topMood: 'happy',
  topTags: ['工作', '运动', '阅读']
}

const weeklyMoods = {
  labels: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
  data: [
    { mood: 'happy', values: [85, 75, 80, 90, 85, 95, 88] },
    { mood: 'calm', values: [70, 80, 75, 65, 70, 75, 80] },
    { mood: 'sad', values: [20, 30, 25, 15, 20, 10, 15] },
    { mood: 'angry', values: [10, 15, 20, 10, 5, 5, 8] }
  ]
}

const moodDistribution = [
  { mood: 'happy', count: 20, percentage: 45 },
  { mood: 'calm', count: 15, percentage: 33 },
  { mood: 'sad', count: 7, percentage: 15 },
  { mood: 'angry', count: 3, percentage: 7 }
]

const recentArtworks = ref([
  {
    id: 1,
    mood: 'happy',
    date: '2024-03-20',
    thumbnail: 'https://placekitten.com/200/200',
    style: 'watercolor'
  },
  {
    id: 2,
    mood: 'calm',
    date: '2024-03-19',
    thumbnail: 'https://placekitten.com/201/200',
    style: 'abstract'
  }
])

const moodTrends = {
  months: ['1月', '2月', '3月'],
  happiness: [70, 75, 82],
  activities: [15, 20, 25]
}

const insights = [
  {
    id: 1,
    title: '积极发现',
    content: '运动和户外活动往往带来更好的心情',
    icon: '🎯'
  },
  {
    id: 2,
    title: '生活建议',
    content: '工作时记得适时休息，有助于保持心情愉悦',
    icon: '💡'
  },
  {
    id: 3,
    title: '情绪模式',
    content: '周末的心情普遍比工作日更好',
    icon: '📊'
  }
]
</script>

<template>
  <div class="insight-center">
    <!-- 顶部统计卡片 -->
    <div class="stats-grid">
      <div class="mood-card stat-card">
        <div class="stat-icon">📝</div>
        <div class="stat-info">
          <div class="stat-value">{{ moodStats.totalEntries }}</div>
          <div class="stat-label">记录总数</div>
        </div>
      </div>
      <div class="mood-card stat-card">
        <div class="stat-icon">😊</div>
        <div class="stat-info">
          <div class="stat-value">{{ moodStats.averageMood }}%</div>
          <div class="stat-label">平均心情指数</div>
        </div>
      </div>
      <div class="mood-card stat-card">
        <div class="stat-icon">🏆</div>
        <div class="stat-info">
          <div class="stat-value">{{ moodStats.topMood }}</div>
          <div class="stat-label">最常见心情</div>
        </div>
      </div>
      <div class="mood-card stat-card">
        <div class="stat-icon">🏷️</div>
        <div class="stat-info">
          <div class="stat-tags">
            <span v-for="tag in moodStats.topTags" :key="tag" class="mood-tag">
              {{ tag }}
            </span>
          </div>
          <div class="stat-label">热门标签</div>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="insight-grid">
      <!-- 周心情趋势图 -->
      <div class="mood-card trend-chart">
        <h3>周心情趋势</h3>
        <div class="chart-container">
          <div class="chart-legend">
            <div v-for="mood in weeklyMoods.data" :key="mood.mood" class="legend-item">
              <span 
                class="legend-color"
                :style="{ background: `var(--mood-${mood.mood})` }"
              ></span>
              {{ mood.mood }}
            </div>
          </div>
          <div class="chart-grid">
            <div 
              v-for="(label, index) in weeklyMoods.labels" 
              :key="label"
              class="chart-column"
            >
              <div 
                v-for="mood in weeklyMoods.data"
                :key="mood.mood"
                class="mood-bar"
                :style="{
                  height: mood.values[index] + 'px',
                  background: `var(--mood-${mood.mood})`
                }"
              ></div>
              <div class="chart-label">{{ label }}</div>
            </div>
          </div>
        </div>
      </div>

      <!-- 心情分布 -->
      <div class="mood-card distribution-chart">
        <h3>心情分布</h3>
        <div class="distribution-container">
          <div 
            v-for="item in moodDistribution"
            :key="item.mood"
            class="distribution-item"
          >
            <div class="distribution-bar">
              <div 
                class="distribution-fill"
                :style="{
                  width: item.percentage + '%',
                  background: `var(--mood-${item.mood})`
                }"
              ></div>
            </div>
            <div class="distribution-info">
              <span class="distribution-mood">{{ item.mood }}</span>
              <span class="distribution-count">{{ item.count }}次</span>
              <span class="distribution-percentage">{{ item.percentage }}%</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 生成的艺术作品 -->
      <div class="mood-card artwork-gallery">
        <h3>近期艺术作品</h3>
        <div class="artwork-grid">
          <div 
            v-for="artwork in recentArtworks"
            :key="artwork.id"
            class="artwork-item"
          >
            <img :src="artwork.thumbnail" :alt="artwork.mood">
            <div class="artwork-info">
              <span class="artwork-mood">{{ artwork.mood }}</span>
              <span class="artwork-date">{{ artwork.date }}</span>
            </div>
          </div>
        </div>
      </div>

      <!-- AI 洞察 -->
      <div class="mood-card insights-section">
        <h3>AI 心情洞察</h3>
        <div class="insights-grid">
          <div 
            v-for="insight in insights"
            :key="insight.id"
            class="insight-card"
          >
            <div class="insight-icon">{{ insight.icon }}</div>
            <div class="insight-content">
              <h4>{{ insight.title }}</h4>
              <p>{{ insight.content }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.insight-center {
  padding: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
}

.stat-icon {
  font-size: 2.5rem;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--primary-color);
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.stat-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2rem;
}

/* 趋势图表样式 */
.trend-chart {
  grid-column: span 2;
}

.chart-container {
  margin-top: 1.5rem;
}

.chart-legend {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.chart-grid {
  height: 200px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-top: 2rem;
}

.chart-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.mood-bar {
  width: 4px;
  border-radius: 2px;
  transition: height 0.3s;
}

/* 分布图表样式 */
.distribution-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.distribution-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.distribution-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.distribution-fill {
  height: 100%;
  transition: width 0.3s;
}

.distribution-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

/* 艺术作品展示样式 */
.artwork-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.artwork-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
}

.artwork-item img {
  width: 100%;
  height: 150px;
  object-fit: cover;
}

.artwork-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
}

/* AI 洞察样式 */
.insights-grid {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

.insight-card {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: rgba(124, 92, 255, 0.05);
  border-radius: 12px;
}

.insight-icon {
  font-size: 2rem;
}

.insight-content h4 {
  margin: 0 0 0.5rem 0;
  color: var(--primary-color);
}

.insight-content p {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.5;
}

h3 {
  color: var(--text-primary);
  font-size: 1.2rem;
  margin: 0;
}
</style> 